import { ROOT } from '@sker/core';
import { join } from 'path';
import { DependencyContainer } from 'tsyringe';
import WxPay from 'wechatpay-node-v3'
export interface WechatPayHandler<T>{
    (wxPay: WxPay):Promise<T>;
}
export const useWechatPay = async <T>(injector: DependencyContainer, handler: WechatPayHandler<T>) => {
    const root = injector.resolve(ROOT)
    const jsonFile = join(`${root}`, 'data/plugins', `@sker/mq.json`)
    const config = require(jsonFile)
    const wxPay = new WxPay({
        appid: config.WECHAT_APPID,
        mchid: config.WECHAT_MCHID,
        publicKey: Buffer.from(config.WECHAT_PUBLIC_KEY, 'utf8'),
        privateKey: Buffer.from(config.WECHAT_PRIVATE_KEY, 'utf8'),
        key: config.WECHAT_API_SECRET,
    })
    const res = await handler(wxPay)
    return res;
}
export default useWechatPay;
